package itheima_edu_info_manager.com.itheima.edu.info.manager.dao;

import itheima_edu_info_manager.com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    private static Student[] stus = new Student[5];
    public boolean addStudent(Student student) {

        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null){
                index = i;
                break;
            }
        }
        if (index == -1){
            return false;
        }else {
            stus[index] = student;
            return true;
        }
    }

    public Student[] findAllStudent() {
        return stus;
    }

    public void deleteStudentById(String id) {
         int index = getindex(id);
         stus[index] = null;
    }

    public int getindex(String id) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if (student != null && student.getId().equals(id)){
                index = i;
                break;
            }
        }
        return index;
    }

    public void upDateStudentById(String id, Student student) {
        int index = getindex(id);
        stus[index] = student;
    }
}
